package xin.fallen.serviceimpl;

import org.springframework.stereotype.Service;
import xin.fallen.bean.WechatEventReport;
import xin.fallen.dao.WechatEventReportMapper;
import xin.fallen.service.PicManagerSer;
import xin.fallen.service.WechatEventReportSer;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Author: Fallen
 * Date: 2017/3/9
 * Time: 21:03
 * Usage:
 */
@Service
public class WeChatEventReportSerImpl implements WechatEventReportSer {

    @Resource
    private WechatEventReportMapper wechatEventReportMapper;
    @Resource
    private PicManagerSer picManagerSerImpl;

    public Integer eventSave(WechatEventReport wer, String token, String code) {
        String rm = getYHDH(token);
        if (rm == null) {
            return null;
        }
        wer.setReportMan(rm);
        wer.setEventPic1(picManagerSerImpl.download(wer.getEventPic1(), code));
        wer.setEventPic2(picManagerSerImpl.download(wer.getEventPic2(), code));
        wer.setEventPic3(picManagerSerImpl.download(wer.getEventPic3(), code));
        wer.setEventPic4(picManagerSerImpl.download(wer.getEventPic4(), code));
        int res = wechatEventReportMapper.insertSelective(wer);
        System.out.println(res);
        return res;
    }

    public String getYHDH(String token) {
        return wechatEventReportMapper.selectYHDHbyToken(token);
    }
}
